﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Windows;

namespace Viinikellari
{
   public static class Xmlstream
    {
        public static void Serialize<T>(string path, T obj)
        {
            using (var writer = new StreamWriter(path))
            {
                XmlTextWriter xmlWriter = new XmlTextWriter(writer);
                xmlWriter.Formatting = Formatting.Indented;

                XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
                xmlSerializer.Serialize(xmlWriter, obj);
            }

        }

        public static T Deserialize<T>(string path)
        {
            object obj;
                using (var reader = new StreamReader(path))
                {
                    XmlTextReader xmlReader = new XmlTextReader(reader);
                    XmlSerializer xmlDeserializer = new XmlSerializer(typeof(T));
                    obj = xmlDeserializer.Deserialize(xmlReader);
                }
                return (T)obj;
        }
    }
}
